

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>广告管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__LAYUI__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__LAYUI__/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <p>{$pos['title']}——{$pos['name']}——{$pos['path']}</p>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-header">添加/编辑广告</div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="component-form-group">
                <input type="hidden" name="id" value="{$adv.id}">
                <div class="layui-form-item">
                    <label class="layui-form-label">广告位ID</label>
                    <div class="layui-input-inline">
                        <input type="text" name="pos_id" value="{$pos.id}" lay-verify="required" placeholder="{$pos.id}" class="layui-input" disabled>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">广告说明</label>
                    <div class="layui-input-inline">
                        <input type="text" name="title" value="{$adv.title}" lay-verify="required" placeholder="广告说明" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">生效时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="start_time" value="{$adv.start_time}" id="LAY-start-date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">失效时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="end_time" value="{$adv.end_time}" id="LAY-end-date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-inline">
                        <input type="text" name="sort" value="{$adv.sort}" placeholder="排序" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">创建时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="create_time" value="{$adv.create_time}" id="LAY-create-date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline">
                        <select name="status">
                            <option value="-1">删除</option>
                            <option value="0">禁用</option>
                            <option value="1" selected>启用</option>
                            <option value="2">未审核</option>
                        </select>
                    </div>
                </div>
                {switch pos.type}
                {case 1|2}
                <div class="layui-form-item">
                    <label class="layui-form-label">图片 </label>
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" id="picture">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                    </div>
                    <div class="layui-input-block">
                        <div id="ImgPreview">
                            <a class="layui-upload-img" style="display:block;width: 190px;height: 100px;padding: 20px 0;"><img style="width: 100%;height: 100%;" src="{$adv.data.pic|pic}" alt=""></a>
                        </div>
                    </div>
                    <input type="hidden" name="pic" value="{$adv.data.pic}" lay-verify="required">
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">链接地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="url" value="{$adv.url}" lay-verify="required" placeholder="链接地址" autocomplete="off" class="layui-input">
                    </div>
                </div>
                {/case}
                {case 3}
                <div class="layui-form-item">
                    <label class="layui-form-label">文字内容</label>
                    <div class="layui-input-block">
                        <input type="text" name="text" value="{$adv.data.text}" lay-verify="required" placeholder="文字内容 （广告展示文字）" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">文字颜色</label>
                    <div class="layui-input-inline" style="width: 120px;">
                        <input type="text" name="text_color" value="{$adv.data.text_color}" placeholder="请选择颜色" class="layui-input" id="color-input">
                    </div>
                    <div class="layui-inline" style="left: -11px;">
                        <div id="color"></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">链接地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="url" value="{$adv.url}" lay-verify="required" placeholder="链接地址" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">文字大小</label>
                    <div class="layui-input-block">
                        <input type="text" name="text_font_size" value="{$adv.data.text_font_size}" lay-verify="required" placeholder="文字大小 （需带单位，例如：14px）" autocomplete="off" class="layui-input">
                    </div>
                </div>
                {/case}
                {case 4}
                <div class="layui-form-item">
                    <label class="layui-form-label">代码内容</label>
                    <div class="layui-input-block">
                        <textarea name="code" placeholder="可填写js、html" lay-verify="required" class="layui-textarea"></textarea>
                    </div>
                </div>
                {/case}
                {/switch}
                <div class="layui-form-item">
                    <label class="layui-form-label">打开方式</label>
                    <div class="layui-input-inline">
                        <select name="target">
                            <option value="_blank">新窗口:_blank</option>
                            <option value="_self">当前层:_self</option>
                            <option value="_parent">父框架:_parent</option>
                            <option value="_top">整个框架:_top</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button id="bindUpload" class="layui-btn" lay-submit="" lay-filter="component-form">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<script src="__LAYUI__/layui/layui.js"></script>
<script>
    layui.config({
        base: '__LAYUI__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate', 'upload', 'colorpicker', 'element'], function(){
        var $ = layui.$
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form
            ,colorpicker = layui.colorpicker
            ,element = layui.element;

        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-start-date'
        });
        laydate.render({
            elem: '#LAY-end-date'
        });
        laydate.render({
            elem: '#LAY-create-date'
        });

        var upload = layui.upload;

        //执行实例
        upload.render({
            elem: '#picture' //绑定元素
            ,url: "{:url('adv/upload')}" //上传接口
            ,auto: true //选择文件后是否自动上传
            ,choose: function(obj) {
                //将每次选择的文件追加到文件队列
                //var files = obj.pushFile();
                obj.preview(function (index, file, result) {
                    $('.layui-upload-img img').attr('src',result);
                })
            }
            ,done: function(res){
                //上传完毕回调
                $('input[name="pic"]').val(res.id);
            }
            ,error: function(){
                //请求异常回调
            }
        });

        /* 监听提交 */
        form.on('submit(component-form)', function(data){
            var field = data.field;
            $.ajax({
                url:"{:url('adv/appendAdv')}",
                type:"POST",
                data:field,
                success:function (res) {
                    layer.msg(res.msg);
                    element.tabDelete(filter, layid);
                }
            });
            return false;
        });

        //颜色选择器
        colorpicker.render({
            elem: '#color'
            ,color: '#009688'
            ,done: function(color){
                $('#color-input').val(color);
            }
        });

        $("select[name='status']").find("option[value='{$adv.status}']").prop("selected",true);
        $("select[name='target']").find("option[value='{$adv.target}']").prop("selected",true);
        form.render();
    });
</script>
</body>
</html>